package com.test.SerializeDemo;

import org.junit.Test;

import java.io.*;

/**
 * ${DESCRIPTION}
 *
 * @author muxiaoyu
 * @create 2017/06/02 10:27
 **/
public class Main {

    /**
     * 对象转二进制流
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Student s1 = new Student("xiaoyu", 50, 100);
        FileOutputStream fileOutputStream = new FileOutputStream(new File("d://1.txt"));
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(s1);
        fileOutputStream.close();
        objectOutputStream.close();
    }

    @Test
    public void test01() throws Exception {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(new File("d://1.txt")));
        Student s1 = (Student) objectInputStream.readObject();
        System.out.println(s1);

    }

    @Test
    public void test02() throws Exception {
        boolean a = false;
        a = 3 != -1;
        System.out.println(a);

    }

    @Test
    public void test002() throws Exception {
        System.out.println(add(1, 2, 3, 4, 5));
    }

    Integer add(Integer... args) {
        Integer count = 0;
        for (Integer arg : args) {
            count += arg;
        }
        return count;
    }

    @Test
    public void testFile() throws Exception {
        File file = new File("d:\\1\\2\\3\\4\\123.txt");
        // System.out.println(file.exists());
        File parentFile = file.getParentFile();
        //mkdirs()方法可以建立多级目录
        boolean mkdir = parentFile.mkdirs();
        System.out.println(mkdir);
        if (!file.exists()) {
            //file.mkdir();
            file.createNewFile();
        }
        System.out.println(file.canExecute());
    }

    @Test
    public void testString() throws Exception {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("d:\\String.txt")));
        String original = "998 is a good number!";
        objectOutputStream.writeObject(original);
    }
}
